package org.javaongems.client.rt.lang;

/**
 * <p>Provides some additional string support to extend GWT emul runtime. This 
 * will progressively have functionality ported from apache commons lang on
 * an as needed basis.</p>
 * 
 * @author Ashin Wimalajeewa ash
 */
public class StringUtils {
	final static public String EMPTY = "";
	
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((CharacterUtils.isWhitespace(str.charAt(i)) == false)) {
                return false;
            }
        }
        return true;
    }
    
    public static String trim(String str) {
        return str == null ? null : str.trim();
    }
    
    public static String trimToNull(String str) {
        String ts = trim(str);
        return isEmpty(ts) ? null : ts;
    }

    public static String trimToEmpty(String str) {
        return str == null ? EMPTY : str.trim();
    }
}
